package com.controller;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;

import com.beans.User;
import com.controller.base.MultiMethodController;
import com.service.impl.UserManagerImpl;
import com.util.DateUtil;
import com.util.MD5;

public class LoginController extends MultiMethodController {
	private UserManagerImpl userManager;

	public UserManagerImpl getUserManager() {
		return userManager;
	}

	public void setUserManager(UserManagerImpl userManager) {
		this.userManager = userManager;
	}

	public ModelAndView checkValidateCode(HttpServletRequest request,
			HttpServletResponse response) {
		String msg = "";
		String inputCode = (String) request.getParameter("value");
		String code = request.getSession().getAttribute("validateCode")
				.toString();
		if (null != inputCode && inputCode.length() > 0
				&& inputCode.toUpperCase().equals(code.toUpperCase())) {
			msg = "{success:true}";
		} else {
			msg = "{success:false}";
		}
		this.getMessage(response, msg);
		return null;
	}

	public ModelAndView userRegister(HttpServletRequest request,
			HttpServletResponse response) {
		String msg = "";
		String name = (String) request.getParameter("name");
		String email = (String) request.getParameter("email");
		String pass = (String) request.getParameter("password");
		//String code = (String) request.getParameter("checkcode");
		User user = new User();
		user.setRegistTime(new Date());
		user.setIp(request.getRemoteAddr());
//		user.setName(name);
		MD5 md5=new MD5();
		user.setPwd(md5.getMD5ofStr(pass));
		user.setEmail(email);
		user.setEnabled("1");
		System.out.println(user);
		userManager.insert(user);
//		user=userManager.checkEmailStat(email);
		msg = "{success:true,id:"+user.getLoginName()+"}";
		this.getMessage(response, msg);
		return null;
	}
}
